#include "threadPool.h"

off_t getOffset(int netfd, const char *filename)
{
    char findFilename[50] = {0};
    strcpy(findFilename, filename);

    // 给文件名加后缀
    strcat(findFilename, ".filepart");

    // 判断当前路径是否存在同名文件
    bool exist = false;
    int ret = open(findFilename, O_RDONLY);
	if (ret != -1)
	{
        exist = true;
    }

    // 如果存在同名需要断点续传的文件
    if(exist == true)
    {
        int fd = open(findFilename, O_RDWR);
        
        // 获取文件大小并发送
        struct stat statbuf;
        fstat(fd, &statbuf);
        send(netfd, &statbuf.st_size, sizeof(statbuf.st_size), MSG_NOSIGNAL);

        return statbuf.st_size;
    }
    else
    {
        off_t offset = 0;
        send(netfd, &offset, sizeof(offset), MSG_NOSIGNAL);

        return 0;
    }

}